home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / misc / print_page.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  12.5 KB  |  391 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Topic display in printable format module
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 25th March 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new Printable;
  26.  
  27. class Printable {
  28.  
  29.     var $output    = "";
  30.     var $base_url  = "";
  31.     var $html      = "";
  32.     var $moderator = array();
  33.     var $forum     = array();
  34.     var $topic     = array();
  35.     var $category  = array();
  36.     var $mem_groups = array();
  37.     var $mem_titles = array();
  38.     var $mod_action = array();
  39.     var $poll_html  = "";
  40.     
  41.     /***********************************************************************************/
  42.     //
  43.     // Our constructor, load words, load skin, print the topic listing
  44.     //
  45.     /***********************************************************************************/
  46.     
  47.     function Printable() {
  48.     
  49.     
  50.         global $ibforums, $DB, $std, $print, $skin_universal;
  51.         
  52.         require "./Skin/".$ibforums->skin_id."/skin_printpage.php";
  53.  
  54.         /***********************************/
  55.         // Compile the language file
  56.         /***********************************/
  57.         
  58.         $ibforums->lang      = $std->load_words($ibforums->lang, 'lang_printpage', $ibforums->lang_id);
  59.  
  60.         $this->html          = new skin_printpage();
  61.         
  62.         /***********************************/
  63.         // Check the input
  64.         /***********************************/
  65.         
  66.         $ibforums->input['t'] = $std->is_number($ibforums->input['t']);
  67.         $ibforums->input['f'] = $std->is_number($ibforums->input['f']);
  68.         
  69.         if ($ibforums->input['t'] < 0 or $ibforums->input['f'] < 0)
  70.         {
  71.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  72.         }
  73.         
  74.         //-------------------------------------
  75.         // Get the forum info based on the forum ID, get the category name, ID, and get the topic details
  76.         //-------------------------------------
  77.         
  78.        $DB->query("SELECT t.*, f.name as forum_name, f.id as forum_id, f.read_perms, f.password, f.reply_perms, f.start_perms, f.allow_poll, f.posts as forum_posts, f.topics as forum_topics, f.use_attach, c.name as cat_name, c.id as cat_id FROM ibf_topics t, ibf_forums f , ibf_categories c where t.tid='".$ibforums->input[t]."' and f.id = t.forum_id and f.category=c.id");
  79.         
  80.         $this->topic = $DB->fetch_row();
  81.         
  82.         $this->forum = array( 'id'           => $this->topic['forum_id']          ,
  83.                               'name'         => $this->topic['forum_name']        ,
  84.                               'posts'        => $this->topic['forum_posts']       ,
  85.                               'topics'       => $this->topic['forum_topics']      ,
  86.                               'read_perms'   => $this->topic['read_perms']        ,
  87.                               'allow_poll'   => $this->topic['allow_poll']        ,
  88.                               'use_attach'   => $this->topic['use_attach']        ,
  89.                               'password'     => $this->topic['password']
  90.                             );
  91.                             
  92.         $this->category = array( 'name'   => $this->topic['cat_name'],
  93.                                  'id'     => $this->topic['cat_id']  ,
  94.                                );
  95.         
  96.         //-------------------------------------
  97.         // Error out if we can not find the forum
  98.         //-------------------------------------
  99.         
  100.         if (!$this->forum['id'])
  101.         {
  102.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  103.         }
  104.         
  105.         //-------------------------------------
  106.         // Error out if we can not find the topic
  107.         //-------------------------------------
  108.         
  109.         if (!$this->topic['tid'])
  110.         {
  111.             $std->Error( array( LEVEL => 1, MSG => 'missing_files') );
  112.         }
  113.         
  114.         
  115.         $this->base_url = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?s={$ibforums->session_id}";
  116.         
  117.         
  118.         /***********************************/
  119.         // Check viewing permissions, private forums,
  120.         // password forums, etc
  121.         /***********************************/
  122.         
  123.         if ( (!$this->topic['pin_state']) and (!$ibforums->member['g_other_topics']) )
  124.         {
  125.             $std->Error( array( LEVEL => 1, MSG => 'no_view_topic') );
  126.         }
  127.         
  128.         $bad_entry = $this->check_access();
  129.         
  130.         if ($bad_entry == 1) {
  131.             $std->Error( array( LEVEL => 1, MSG => 'no_view_topic') );
  132.         }      
  133.         
  134.         
  135.         
  136.         
  137.  
  138.         /***********************************/
  139.         // Render the page top
  140.         /***********************************/
  141.         
  142.         $this->output .= $this->html->pp_header( $this->forum['name'], $this->topic['title'], $this->topic['starter_name'] );
  143.  
  144.  
  145.         /*******************************************************************************************/
  146.         // Grab the posts we'll need
  147.         /*******************************************************************************************/
  148.         
  149.         // Set a prohibitive limit delibrately for long topics.
  150.         
  151.         $max_posts = 300;
  152.         
  153.         $DB->query( "SELECT * FROM ibf_posts WHERE topic_id='".$this->topic['tid']."'".
  154.                     " and queued !='1' ORDER BY pid LIMIT 0, ".$max_posts);
  155.                     
  156.         // Loop through to pick out the correct member IDs.
  157.         // and push the post info into an array - maybe in the future
  158.         // we can add page spans, or maybe save to a PDF file?
  159.         
  160.         $the_posts      = array();
  161.         $mem_ids        = "";
  162.         $member_array   = array();
  163.         $cached_members = array();
  164.         
  165.         while ($i = $DB->fetch_row() )
  166.         {
  167.             $the_posts[] = $i;
  168.             if ($i['author_id'] != 0)
  169.             {
  170.                 if (preg_match( "/'".$i['author_id']."',/", $mem_ids) )
  171.                 {
  172.                     continue;
  173.                 }
  174.                 else
  175.                 {
  176.                     $mem_ids .= "'".$i['author_id']."',";
  177.                 }
  178.             }
  179.         }
  180.         
  181.         // Fix up the member_id string
  182.         $mem_ids = preg_replace( "/,$/", "", $mem_ids);
  183.         
  184.         // Get the member profiles needed for this topic
  185.         
  186.         if ($mem_ids != "")
  187.         {
  188.             $DB->query("SELECT id,name,mgroup,email,joined,ip_address,avatar,avatar_size,posts,aim_name,icq_number,signature,
  189.                                website,yahoo,title,hide_email,msnname from ibf_members WHERE id in ($mem_ids)");
  190.     
  191.             while ( $m = $DB->fetch_row() )
  192.             {
  193.                 if ($m['id'] and $m['name'])
  194.                 {
  195.                     if (isset($member_array[ $m['id'] ]))
  196.                     {
  197.                         continue;
  198.                     }
  199.                     else
  200.                     {
  201.                         $member_array[ $m['id'] ] = $m;
  202.                     }
  203.                 }
  204.             }
  205.         }
  206.         
  207.         /***********************************/
  208.         // Format and print out the topic list
  209.         /***********************************/
  210.         
  211.         $td_col_cnt = 0;
  212.         
  213.         foreach ($the_posts as $row) {
  214.         
  215.             $poster = array();
  216.         
  217.             // Get the member info. We parse the data and cache it.
  218.             // It's likely that the same member posts several times in
  219.             // one page, so it's not efficient to keep parsing the same
  220.             // data
  221.             
  222.             if ($row['author_id'] != 0)
  223.             {
  224.                 // Is it in the hash?
  225.                 if ( isset($cached_members[ $row['author_id'] ]) )
  226.                 {
  227.                     // Ok, it's already cached, read from it
  228.                     $poster = $cached_members[ $row['author_id'] ];
  229.                     $row['name_css'] = 'normalname';
  230.                 }
  231.                 else
  232.                 {
  233.                     // Ok, it's NOT in the cache, is it a member thats
  234.                     // not been deleted?
  235.                     if ($member_array[ $row['author_id'] ])
  236.                     {
  237.                         $row['name_css'] = 'normalname';
  238.                         $poster = $member_array[ $row['author_id'] ];
  239.                         // Add it to the cached list
  240.                         $cached_members[ $row['author_id'] ] = $poster;
  241.                     }
  242.                     else
  243.                     {
  244.                         // It's probably a deleted member, so treat them as a guest
  245.                         $poster = $std->set_up_guest( $row['author_id'] );
  246.                         $row['name_css'] = 'unreg';
  247.                     }
  248.                 }
  249.             }
  250.             else
  251.             {
  252.                 // It's definately a guest...
  253.                 $poster = $std->set_up_guest( $row['author_name'] );
  254.                 $row['name_css'] = 'unreg';
  255.             }
  256.             
  257.             //--------------------------------------------------------------
  258.             
  259.             $row['post_css'] = $td_col_count % 2 ? 'post1' : 'post2';
  260.             
  261.             ++$td_col_count;
  262.             
  263.             //--------------------------------------------------------------
  264.             
  265.             if (!$ibforums->skin[EDIT_FONT_SIZE]) $ibforums->skin[EDIT_FONT_SIZE] = 7;
  266.             
  267.             $row['post'] = preg_replace( "/<!--EDIT\|(.+?)\|(.+?)-->/", "<span style='font-size:$ibforums->skin[EDIT_FONT_SIZE]pt'>Edited by \\1 on \\2</span>", $row['post'] );
  268.             
  269.             //--------------------------------------------------------------
  270.             
  271.             if (!$ibforums->member['view_img'])
  272.             {
  273.                 $row['post'] = preg_replace( "/<img src[\"'](.+?)[\"'].+?".">/", "(IMG:<a href='\\1' target='_blank'>\\1</a>)", $row['post'] );
  274.             }
  275.             
  276.         
  277.             
  278.             $row['post_date']   = $std->get_date( $row['post_date'], 'LONG' );
  279.             
  280.             $row['post'] = $this->parse_message($row['post']);
  281.             
  282.                               
  283.             //--------------------------------------------------------------
  284.             // Siggie stuff
  285.             //--------------------------------------------------------------
  286.             
  287.             if (!$ibforums->vars[SIG_SEP]) $ibforums->vars[SIG_SEP] = "<br><br>--------------------<br>";
  288.             
  289.             if ($poster['signature'] and $ibforums->member['view_sigs'])
  290.             {
  291.                 if ($row['use_sig'] == 1)
  292.                 {
  293.                     $row['signature'] = "<!--Signature-->{$ibforums->vars[SIG_SEP]}<span id='signature'>{$poster['signature']}</span><!--E-Signature-->";
  294.                 }
  295.                                 
  296.             }
  297.             
  298.             $this->output .= $this->html->pp_postentry( $poster, $row );
  299.             
  300.         }
  301.         
  302.         /***********************************/
  303.         // Print the footer
  304.         /***********************************/
  305.         
  306.         $this->output .= $this->html->pp_end();
  307.         
  308.         /***********************************/
  309.         // Print all the output
  310.         /***********************************/
  311.         
  312.         $this->output .= "<br><br><font size='1'><center>Powered by Invision Board<br>© 2002 Invision PS</center></font></body></html>";
  313.         
  314.         
  315.         echo($this->output);
  316.         
  317.         exit;
  318.         
  319.                         
  320.     }
  321.     
  322.  
  323.     function parse_message($message="") {
  324.     
  325.         $message = preg_replace( "#<!--emo&(.+?)-->.+?<!--endemo-->#", "\\1" , $message );
  326.         
  327.         $message = preg_replace( "#<!--c1-->(.+?)<!--ec1-->#", "\n\n------------ CODE SAMPLE ----------\n"  , $message );
  328.         $message = preg_replace( "#<!--c2-->(.+?)<!--ec2-->#", "\n-----------------------------------\n\n"  , $message );
  329.         
  330.         $message = preg_replace( "#<!--QuoteBegin-->(.+?)<!--QuoteEBegin-->#"                       , "\n\n------------ QUOTE ----------\n" , $message );
  331.         $message = preg_replace( "#<!--QuoteBegin--(.+?)\+(.+?)-->(.+?)<!--QuoteEBegin-->#"         , "\n\n------------ QUOTE ----------\n" , $message );
  332.         $message = preg_replace( "#<!--QuoteEnd-->(.+?)<!--QuoteEEnd-->#"                           , "\n-----------------------------\n\n" , $message );
  333.         
  334.         $message = preg_replace( "#<!--Flash (.+?)-->.+?<!--End Flash-->#e"                         , "(FLASH MOVIE)" , $message );
  335.         $message = preg_replace( "#<img src=[\"'](\S+?)['\"].+"."?".">#"                            , "(IMAGE: \\1)"   , $message );
  336.         $message = preg_replace( "#<a href=[\"'](http|https|ftp|news)://(\S+?)['\"].+?".">(.+?)</a>#"  , "(URL: \\1://\\2)"     , $message );
  337.         $message = preg_replace( "#<a href=[\"']mailto:(.+?)['\"]>(.+?)</a>#"                       , "(EMAIL: \\2)"   , $message );
  338.         
  339.         $message = preg_replace( "#<!--sql-->(.+?)<!--sql1-->(.+?)<!--sql2-->(.+?)<!--sql3-->#e"    , "\n\n--------------- SQL -----------\n\\2\n----------------\n\n", $message);
  340.         $message = preg_replace( "#<!--html-->(.+?)<!--html1-->(.+?)<!--html2-->(.+?)<!--html3-->#e", "\n\n-------------- HTML -----------\n\\2\n----------------\n\n", $message);
  341.         
  342.         return $message;
  343.         
  344.     }
  345.     
  346.     function check_access() {
  347.         global $ibforums, $std, $HTTP_COOKIE_VARS;
  348.         
  349.         $return = 1;
  350.         
  351.         $this->m_group = $ibforums->member['mgroup'];
  352.         
  353.         if ($this->forum['read_perms'] == '*')
  354.         {
  355.             $return = 0;
  356.         }
  357.         else if (preg_match( "/(^|,)$this->m_group(,|$)/", $this->forum['read_perms'] ) )
  358.         {
  359.             $return = 0;
  360.         }
  361.         
  362.         if ($this->forum['password'] != "")
  363.         {
  364.         
  365.             if ( ! $c_pass = $std->my_getcookie('iBForum'.$this->forum['id']) )
  366.             {
  367.                 return 1;
  368.             }
  369.         
  370.             if ( $c_pass == $this->forum['password'] )
  371.             {
  372.                 return 0;
  373.             }
  374.             else
  375.             {
  376.                 return 1;
  377.             }
  378.         }
  379.         
  380.         return $return;
  381.     
  382.     }
  383. }
  384.  
  385. ?>
  386.  
  387.  
  388.  
  389.  
  390.  
  391.